package com.tongcao.cn.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * @Author:tongcao
 * @Date:2018/8/25 17:52
 * Description:多任务--异步执行
 */
@Configuration
public class ScheduleConfig implements SchedulingConfigurer {


    @Override
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        scheduledTaskRegistrar.setScheduler(buildTaskExecutors());

    }

    @Bean(destroyMethod = "shutdown")
    public Executor buildTaskExecutors() {
        return Executors.newScheduledThreadPool(3);
    }
}
